<template>
  <section class='f-shop'>
    <van-cell-group class="f-cell-group">
      <van-cell class="f-shop-name">
        <template #title>
          <section class="f-name-title">
            <img class="f-img1" src="@/assets/icons/jhh_store_icon.png" alt="">
            <p class="f-text1">{{shopForm.shopName}}</p>
          </section>
        </template>
      </van-cell>
      <van-cell title="店铺联系人" :value="shopForm.contactsName" />
      <van-cell title="联系电话" :value="shopForm.contactsPhone" />
    </van-cell-group>

    <van-cell-group class="f-cell-group f-mt-14">
      <van-cell title="店铺类型" :value="shopForm.shopType">
        <template #value>
          <p>{{shopForm.shopType == 1? '个人': '公司'}}</p>
        </template>
      </van-cell>
      <van-cell title="企业名称" :value="shopForm.companyName">
        <template #value>
          <p>{{shopForm.companyName || '--'}}</p>
        </template>
      </van-cell>
    </van-cell-group>

    <div class="f-submit-btn">
      <van-button round block type="primary" @click="setBindSupplier">添加为供应商</van-button>
    </div>
  </section>
</template>
<script>
import { ref, reactive, toRefs, onMounted, watch } from 'vue';
import { useRouter, useRoute } from 'vue-router'
import { useStore } from "vuex";
import { getStore, successDeal } from '@/utils/utils';
import QrcodeVue from 'qrcode.vue'
import api from '../api'

export default {
  components: { QrcodeVue },

  setup(props, context) {
    const store = useStore()

    const router = useRouter()
    const route = useRoute();

    const state = reactive({
      shopForm: {},
    })

    onMounted(() => {
      store.commit("setNavBar", {
        title: '店铺信息',
        show: true,
        left: true,
        leftType: 'back',
        right: false,
        rightType: 'search',
      });

      getShopInfo(route.query.shopId)
    })

    const getShopInfo = (shopId) => {
      let json = {
        shopId
      }
      api.shopQrInfo(json).then(res => {
        state.shopForm = res.data
        console.log(res.data)
      })
    }

    const setBindSupplier = () => {
      let json = {
        shopCode: state.shopForm.shopCode
      }
      api.bindSupplier(json).then(res => {
        successDeal('绑定供应商成功！')
        setTimeout(() => {
          router.go(-1)
        }, 1000)
      })
    }

    return {
      ...toRefs(state),
      setBindSupplier
    }
  }
}
</script>
<style lang='scss' scoped>
.f-shop {
  padding: 11px 16px;
  .f-cell-group {
    width: 344px;
    padding: 5px;
    background: #ffffff;
    box-shadow: 0px 2px 6px 0px rgba(0, 51, 119, 0.1);
    border-radius: 10px;
    .f-shop-name {
      height: 70px;
      display: flex;
      align-items: center;
      .f-name-title {
        display: flex;
        align-items: center;
        position: absolute;
        top: 7px;
      }
    }
  }
  .f-img1 {
    width: 54px;
    height: 54px;
  }
  .f-text1 {
    font-size: 17px;
    font-weight: 500;
    color: #000000;
    margin-left: 8px;
  }
  .f-img2 {
    width: 159px;
    height: 102px;
    position: relative;
  }
  .f-fxs {
    background-image: url("@/assets/imgs/jhh_store_btn_fxs.png");
    background-size: 100%;
  }
  .f-gys {
    background-image: url("@/assets/imgs/jhh_store_btn_gys.png");
    background-size: 100%;
  }
  .f-absolute {
    position: absolute;
    top: 36px;
    left: 17px;
  }
  .f-text2 {
    font-size: 16px;
    font-weight: 500;
    color: #ffffff;
  }
  .f-text3 {
    font-size: 10px;
    color: #ffffff;
    margin-top: 9px;
  }
  .f-img3 {
    width: 344px;
    height: 73px;
    margin-top: 14px;
    margin-bottom: 10px;
    background-image: url("@/assets/imgs/jhh_store_btn_service.png");
    background-size: 100%;
  }

  .f-text4 {
    font-size: 16px;
    font-weight: 500;
    color: #000000;
    padding: 16px 18px;
  }

  .f-mt-14 {
    margin-top: 14px;
  }

  .f-submit-btn {
    margin-top: 70px;
    padding: 0 40px;
  }
}
</style>